package cn.hsa.xxx.approve.service.impl;


import cn.hsa.hsaf.core.mq.MQBusinessHandler;
import cn.hsa.hsaf.core.mq.MQMessage;
import cn.hsa.xxx.api.dto.ShelvesApprovalProcessDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayDeque;
import java.util.Queue;

/**
 * 消息队列业务处理对象
 * @author chj
 */

@Slf4j
@Service
public class MqDtoConsumerServiceImpl implements MQBusinessHandler {

    private Queue<ShelvesApprovalProcessDTO> dtoQueue = new ArrayDeque<>();

    @Override
    public boolean doBusiness(MQMessage<?> mqMessage) {
        try {
            String topic = mqMessage.getTopic();
            log.debug("doBusiness:topic:{}",topic);
            ShelvesApprovalProcessDTO content = (ShelvesApprovalProcessDTO)mqMessage.getContent();
            log.debug("doBusiness:content:{}",content);
            dtoQueue.add(content);
            log.info("DEMO接收消息队列，业务处理成功，消息主题：{}，消息内容：{}。", topic, content);
            return true;
        } catch (Exception e) {
            log.error("DEMO接收消息队列，业务处理失败: {} ", e);
            return false;
        }
    }

    public Queue<ShelvesApprovalProcessDTO> getDtoQueue() {
        return dtoQueue;
    }
}
